<script setup>
import {ref, onMounted, watch} from "vue";
import NavMenu from "../components/navMenu.vue";
import Header from "../components/headerNav.vue";
import router from "@/router";

let token = ref("");

watch(() =>router.currentRoute.value.path,(newValue,oldValue)=> {
  if (!localStorage.getItem("token")) {
    token.value = ''
    router.push("/login");
  }
  else token.value = localStorage.getItem("token");
},{ immediate: true })

</script>

<template>
  <div class="common-layout">
    <el-container v-if="token">
      <el-container>
        <!-- 头部 -->
        <el-header>
          <Header/>
        </el-header>
        <el-main style="overflow: hidden;">
          <NavMenu/>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
    <router-view v-else/>
  </div>

</template>

<style scoped>

</style>
